package com.yanqu.road.server.manger.activity.auto.send;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UnionActivityConditionData;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.logic.bussiness.player.UserActivityBussiness;
import com.yanqu.road.pb.activity.AutoSendRewardProto;

import java.util.*;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/10 15:25
 */
public class SeacraftSouthSeaActivityAutoSend extends BaseAutoSendActivity {
    public SeacraftSouthSeaActivityAutoSend(ActivityInfo activityInfo) {
        super(activityInfo);
    }

    @Override
    public void sendLocalUserRankReward() {

    }

    @Override
    public void sendLocalUnionRankReward() {

    }

    @Override
    protected boolean updateConditionData(UserActivityConditionData data) {
        return UserActivityBussiness.updateUserActivityConditionData(data);
    }

    @Override
    public void sendConditionReward() {

    }
    /**
     * 通知跨服返回跨服商会榜单
     */
//    @Override
//    public void noticeCrossUnionRank() {
//        // 海盗之乱
//        super.noticeCrossUnionRank();
//    }

    @Override
    public List<UserActivityConditionData> getNeedSendUserActivityConditionData() {
        return null;
    }

    @Override
    public Map<String, UnionActivityConditionData> getUnionActivityConditionData(int conditionType) {
        // 海盗之乱
        return UserActivityBussiness.getUnionActivityConditionDataMap(activityInfo.getActivityId(), conditionType);
    }

    @Override
    public Map<Long, UserActivityConditionData> getUserActivityRankConditionData(int activityId, int conditionType) {
        return getUserNormalActivityRankConditionData(activityId, conditionType);
    }

    /**
     * 发送跨服商会排行奖励
     * @param dataList
     */
    @Deprecated
    public void sendSeacraftSouthSeaCrossUnionRankReward(List<AutoSendRewardProto.UnionRankWithUnionInfoMsg> dataList) {
//        if (dataList.size() <= 0) {
//            AutoSendActivity.getLogger().info("activity unionRank data size is 0, activityId:{}, activityName:{}", activityInfo.getActivityId(), activityInfo.getActivityName());
//        } else {
//            Map<Integer, List<AutoSendRewardProto.UnionRankWithUnionInfoMsg>> userRankMsgMap = new HashMap<>();
//            for (AutoSendRewardProto.UnionRankWithUnionInfoMsg msg : dataList) {
//                int conditionType = msg.getConditionType();
//                String unionId = msg.getUnionId();
//                CrossUnionInfo unionInfo = CrossUnionMgr.getUnionInfo(unionId);
//                if (unionInfo != null && unionInfo.getServerId() == GameServer.getInstance().getServerId()) {
//                    List<AutoSendRewardProto.UnionRankWithUnionInfoMsg> list = userRankMsgMap.get(conditionType);
//                    if (list == null) {
//                        list = new ArrayList<>();
//                        userRankMsgMap.put(conditionType, list);
//                    }
//                    list.add(msg);
//                }
//            }
//            for (Map.Entry<Integer, List<AutoSendRewardProto.UnionRankWithUnionInfoMsg>> entry : userRankMsgMap.entrySet()) {
//                Integer conditionType = entry.getKey();
//                Map<Long, UserActivityConditionData> conditionDataMap = getUserActivityRankConditionData(activityInfo.getActivityId(), conditionType);
//                List<AutoSendRewardProto.UnionRankWithUnionInfoMsg> rankMsgList = entry.getValue();
//                for (AutoSendRewardProto.UnionRankWithUnionInfoMsg msg : rankMsgList) {
//                    for (UserActivityConditionData data : conditionDataMap.values()) {
//                        long userId = data.getUserId();
//                        if (!msg.getMemberIdList().contains(userId)) {
//                            continue;
//                        }
//                        if (data.isGetReward()) {
//                            continue;
//                        }
//                        data.setGetReward(true);
//                        int rank = msg.getRank();
//                        ActivityConditionInfo conditionInfo = getUserRankCondition(conditionType, rank);
//                        if (conditionInfo != null && updateConditionData(data)) {
//                            String rewardStr;
//                            if (userId == msg.getMasterId()) {
//                                rewardStr = conditionInfo.getMasterRewardStr();
//                            } else {
//                                //根据职位获取奖励
//                                rewardStr = conditionInfo.getRewardStr();
//                            }
//                            AutoSendActivity.getLogger().info("autoSend unionReward, user: {}, activity: {},conditionType: {}, rank: {}, reward: {}", userId, activityInfo.getActivityId(), conditionType, rank, rewardStr);
//                            sendMailReward(userId, rewardStr);
//                        }
//                    }
//                }
//            }
//        }
        AutoSendActivity.changeSendState(activityInfo.getActivityId(), 2, 1);
    }

    @Override
    public void noticeCrossUserRank() {
        List<String> typeList = new ArrayList<>();
        typeList.add(String.valueOf(eGamePlayerEventType.SeacraftPirateRiotScoreRank.getValue()));
        typeList.add(String.valueOf(eGamePlayerEventType.SeacraftSouthSeaUserScoreRank.getValue()));
        noticeCrossUserYRank(typeList);
    }

    @Override
    public void noticeCrossUnionRank() {
        List<String> typeList = new ArrayList<>();
        typeList.add(String.valueOf(eGamePlayerEventType.SeacraftPirateRiotUnionScoreRank.getValue()));
        noticeCrossUnionYRank(typeList);

        noticeCrossUnionRankByCrossServer();
    }


}
